# -*- coding:UTF-8 -*-

import urllib
import re


# 获取网页的函数
def getHtml(url):
    page = urllib.urlopen(url)
    html = page.read()
    return html


# 获取图片列表的函数，并对图片列表进行遍历，然后将图片存盘到本地
def getImg(html, count):
    #    reg = r'"http.+?\.jpg'
    imgre = re.compile(r'src="(http.+?\.jpg)">')
    imglist = re.findall(imgre, html)
    x = 0
    for imgurl in imglist:
        urllib.urlretrieve(imgurl, '_picture_JM_%s_%s.jpg' % (x, count))
        x += 1


# html = getHtml("http://tieba.baidu.com/p/2460150866")

# html = getHtml("http://tieba.baidu.com/p/4537424378")

if __name__ == "__main__":
    count = 0
    html = getHtml("http://www.gamersky.com/ent/201605/752759.shtml")
    getImg(html, count)
    count += 1
    for i in range(2, 10):
        url = "http://www.gamersky.com/ent/201605/752759_%d.shtml" % (i)
        print "开始抓取", url
        html1 = getHtml(url)
        count += 1
        getImg(html1, count)